#include "p33Fxxxx.h"
#include "FSIO.h"

#define bfrsize 5

// Clock-Settings aus MotorControl Projekt
// Select Internal FRC at POR
_FOSCSEL(FNOSC_FRC);

// Enable Clock Switching and Configure
_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF);

_FWDT(FWDTEN_OFF); // Watchdog Timer Enabled/disabled by user software


int main(void)
{
    /*
    int i,j;

    TRISAbits.TRISA2 = 0;
    TRISAbits.TRISA3 = 0;
    while(1){

        for(i=0; i<10000; i++)//{
            for(j=0; j<100; j++);
        //}
        PORTAbits.RA2 ^= 1;
        PORTAbits.RA3 ^= 1;

    }
*/
        
        int i = 0;
	FSFILE *pOldFile, *pNewFile;
	char myData[20];
	char bfr [6];
	int bytesRead, bytesWritten;
	char newFile[] = "newfile.txt";
	char writeArg[] = "w";

        // Generate Data
        for(i = 0; i<20; i++){
            myData[i] = 'g' + i;
        }
	// Must initialize the FAT16/FAT32 library. It also initializes SPI and other related pins.
	if( !FSInit() )
		// Failed to initialize FAT16 � do something�
		return 1; // Card not present or wrong format

	// Create a new file
	pNewFile = FSfopen (newFile, writeArg);
	// Open an existing file to read

        FSfwrite( (void *) myData, 20, 1, pNewFile);
	//FSfclose( pOldFile );
	FSfclose (pNewFile);
	//Delete the old file
	//FSremove ("myfile.txt");

        pNewFile = FSfopen (newFile, "a");
        FSfwrite( (void *) "\n append \n", 20, 1, pNewFile);
        FSfclose(pNewFile);

        pNewFile = FSfopen(newFile, "a");


while(1){
    int i,j;

        for(i=0; i<10000; i++)//{
            for(j=0; j<100; j++);
        //}
        PORTAbits.RA2 ^= 1;
        PORTAbits.RA3 ^= 1;

    }




}
/******************************************************************************/

